//////////////////////////////////////////////////////////////////////////////////
//
//	avamods glow
//		- Version 0.4
//		- 08.06.2006
//		- diamond-optic
//
//////////////////////////////////////////////////////////////////////////////////
//
// Information:
//
// 	- type /glow in chat to access the menu
//
// Credits:
//
//   - Based off of FireWalker877's Glow Menu
//   - Color codes from Ultra Glow by Remo Williams
//   - Trail code from GAIO by Zenith77
//
// CVARs & Commands: 
//
//	avamods_glow "1" //turn ON(1) or OFF(2)
//	avamods_glow_trail "0" //trail - ON(1) or OFF(2)
//	avamods_glow_trail_length "1" //length of trail
//
//	avamods_glow_toggle //toggle glow on/off
//
// Extra:
//
//    - There are some problems with the trail, it starts
//	to build up on itself and gets brighter, then if
//	you stop moving for a while, the trail goes away..
//
// Changelog:
//
//   - 06.24.2006 Version 0.1
//  	  Intial Version
//
//   - 06.25.2006 Version 0.2
//  	  Expanded amount of colors
//
//   - 06.26.2006 Version 0.3
//  	  Added trail
//
//   - 06.26.2006 Version 0.3b
//  	  Added is_user_alive check to trail
//
//   - 06.27.2006 Version 0.3c
//  	  Think i really fixed dead/spectator trail bug
//	  New method for setting glow/trail
//	  Added trail on/off thru menu
//
//   - 07.21.2006 Version 0.3d
//  	  Fixed compile error cuase FUN module was commented out (thanks no0bomatic)
//
//   - 08.06.2006 Version 0.4
//  	  Cleaned up code a bit
//	  Added a few new precautionary chceks
//	  Changed some returns  
//
//////////////////////////////////////////////////////////////////////////////////

#include <amxmodx>
#include <fun>
#include <dodx>

#define TASK_TRAIL 2841309

new g_MenuPos[33],p_avamods_glow,g_Sprite,p_avamods_glow_trail,p_avamods_glow_trail_length, trail_color[33][3], in_trail[33]

public plugin_init() 
{ 
   register_plugin("avamods glow","0.4","diamond-optic")
   
   register_cvar("avamods_glow_stats", "0.4", FCVAR_SERVER|FCVAR_SPONLY)
   
   register_menucmd(register_menuid("avamods_glow_menu"),1023,"GlowMenuChoice") 
   
   register_concmd("say /glow","chat_menu",0,"- shows glowing menu")
   register_concmd("say_team /glow","chat_menu",0,"- shows glowing menu") 
   
   register_concmd("avamods_glow_toggle","toggle_glow",ADMIN_LEVEL_B,"- Toggle Glow Menu On and Off") 
   
   p_avamods_glow = register_cvar("avamods_glow","1") 
   p_avamods_glow_trail = register_cvar("avamods_glow_trail","1") 
   p_avamods_glow_trail_length = register_cvar("avamods_glow_trail_length","1")
   
   register_event("ResetHUD","respawn","be")
   register_statsfwd(XMF_DEATH)
   
   register_event("TextMsg","switch_team","a","1=3","2=#game_joined_team","4=Axis")
   register_event("TextMsg","switch_team","a","1=3","2=#game_joined_team","4=Allies")
   register_event("TextMsg","switch_team","a","1=3","2=#game_joined_team","4=Spectators")
}

public plugin_precache()
{
	g_Sprite = precache_model("sprites/laserbeam.spr")
}

public client_disconnect(id)
{
	if(task_exists(id))
		remove_task(id)
	
	if(in_trail[id] == 1)
		in_trail[id] = 0
}

public toggle_glow(id) 
{ 
	if(get_pcvar_num(p_avamods_glow)==1 && is_user_connected(id) && !is_user_bot(id)) 
		{
		set_pcvar_num(p_avamods_glow,0)
		client_print(0,print_chat,"Glow Menu has been disabled!") 
		
		new players[32], num
		get_players(players, num)
	    
		for(new i = 1; i < num; i++)
			{
			set_user_rendering(players[i],kRenderFxGlowShell,0,0,0,kRenderNormal,0)
			
			if(get_pcvar_num(p_avamods_glow_trail) == 1 && in_trail[id] == 1)
				end_trail(id)
			}
		}
	else if(get_pcvar_num(p_avamods_glow)==0 && is_user_connected(id) && !is_user_bot(id)) 
		{
		set_pcvar_num(p_avamods_glow,1)
		client_print(0,print_chat,"Glow Menu has been enabled! Type /glow in chat to access...") 		 
		}
	return PLUGIN_CONTINUE 
}

public chat_menu(id) 
{
	if(is_user_connected(id) && !is_user_bot(id) && get_pcvar_num(p_avamods_glow)!=1) 
		client_print(id,print_chat,"Glow Menu is currently disabled")
	else if(!is_user_alive(id) && !is_user_bot(id))
		client_print(id,print_chat,"You must be alive to access the glow menu")	
	else if(is_user_connected(id) && is_user_alive(id) && !is_user_bot(id))
		GlowMenuMenu(id,g_MenuPos[id] = 0)

	return PLUGIN_HANDLED
}

public amx_glowmenu(id)
{
	if(is_user_connected(id) && is_user_alive(id) && !is_user_bot(id) && get_pcvar_num(p_avamods_glow) == 1)
		GlowMenuMenu(id,g_MenuPos[id] = 0)

	return PLUGIN_CONTINUE 
}

public GlowMenuMenu(id,pos) 
{
	if(is_user_connected(id) && is_user_alive(id) && !is_user_bot(id) && get_pcvar_num(p_avamods_glow) == 1)
		{ 
		new menuBody[1024] 
		new key
		
		switch(pos)
			{
			case 0: format(menuBody, 1023, "avamods glow menu^n^n 1.  Red^n 2.  Dark Red^n 3.  Light Red^n 4.  Blue^n 5.  Dark Blue^n 6.  Light Blue^n 7.  Green^n 8.  Dark Green^n 9.  Light Green^n^n 0.  Next.", -1, "avamods_glow_menu") 
			case 1: format(menuBody, 1023, "avamods glow menu^n^n 1.  Yellow^n 2.  Dark Yellow^n 3.  Light Yellow^n 4.  Orange^n 5.  Dark Orange^n 6.  Light Orange^n 7.  Brown^n 8.  Light Brown^n^n 9.  Back^n 0.  Next.", -1, "avamods_glow_menu")
			case 2: format(menuBody, 1023, "avamods glow menu^n^n 1.  Purple^n 2.  Dark Purple^n 3.  Light Purple^n 4.  Pink^n 5.  Violet^n 6.  Aqua^n 7.  Maroon^n 8.  White^n^n 9.  Back^n 0.  Next.", -1, "avamods_glow_menu") 
			case 3: format(menuBody, 1023, "avamods glow menu^n^n 1.  Grey^n 2.  Gold^n 3.  Silver^n 4.  Bronze^n^n 5.  Turn glow trail on^n 6.  Turn glow trail off^n^n 7.  Turn glow off^n^n 9.  Back^n 0.  Exit.", -1, "avamods_glow_menu")
			}		
		key = (1<<0)|(1<<1)|(1<<2)|(1<<3)|(1<<4)|(1<<5)|(1<<6)|(1<<7)|(1<<8)|(1<<9)
		
		show_menu(id, key, menuBody, -1, "avamods_glow_menu") 
		} 
} 

public GlowMenuChoice(id, key) 
{ 
   if(is_user_connected(id) && is_user_alive(id) && !is_user_bot(id) && get_pcvar_num(p_avamods_glow) == 1)
	{	
	switch (key)
		{
		case 0:
			{
			new color_name[16]
			
			switch(g_MenuPos[id])
				{			
				case 0: {
					trail_color[id] = {255,0,0}
					color_name = "Red"
					}
				case 1: {
					trail_color[id] = {255,255,0}
					color_name = "Yellow"
					}
				case 2: {
					trail_color[id] = {255,0,255}
					color_name = "Purple"
					}
				case 3: {
					trail_color[id] = {114,114,114}
					color_name = "Grey"
					}		
				}	
			set_hudmessage(trail_color[id][0],trail_color[id][1],trail_color[id][2], 0.02, 0.73, 0, 6.0, 8.0, 0.1, 0.2, 4) 
			show_hudmessage(id, "you are now glowing %s",color_name)
			set_user_rendering(id,kRenderFxGlowShell,trail_color[id][0],trail_color[id][1],trail_color[id][2],kRenderNormal,50)
			
			if(get_pcvar_num(p_avamods_glow_trail) == 1 && in_trail[id] == 1)
				glow_trail(id)
			}
		case 1:
			{
			new color_name[16]
			
			switch(g_MenuPos[id])
				{
				case 0: {
					trail_color[id] = {165,0,0}
					color_name = "Dark Red"
					}
				case 1: {
					trail_color[id] = {189,182,0}
					color_name = "Dark Yellow"
					}
				case 2: {
					trail_color[id] = {150,0,150}
					color_name = "Dark Purple"
					}
				case 3: {
					trail_color[id] = {220,220,0}
					color_name = "Gold"
					}
				}
			set_hudmessage(trail_color[id][0],trail_color[id][1],trail_color[id][2], 0.02, 0.73, 0, 6.0, 8.0, 0.1, 0.2, 4) 
			show_hudmessage(id, "you are now glowing %s",color_name)
			set_user_rendering(id,kRenderFxGlowShell,trail_color[id][0],trail_color[id][1],trail_color[id][2],kRenderNormal,50)
			
			if(get_pcvar_num(p_avamods_glow_trail) == 1 && in_trail[id] == 1)
				glow_trail(id)
			}
		case 2:
			{
			new color_name[16]
			
			switch(g_MenuPos[id])
				{
				case 0: {
					trail_color[id] = {255,100,100}
					color_name = "Light Red"
					}
				case 1: {
					trail_color[id] = {255,255,109}
					color_name = "Light Yellow"
					}
				case 2: {
					trail_color[id] = {243,138,255}
					color_name = "Light Purple"
					}
				case 3: {
					trail_color[id] = {192,192,192}
					color_name = "Silver"
					}
				}		
			set_hudmessage(trail_color[id][0],trail_color[id][1],trail_color[id][2], 0.02, 0.73, 0, 6.0, 8.0, 0.1, 0.2, 4) 
			show_hudmessage(id, "you are now glowing %s",color_name)
			set_user_rendering(id,kRenderFxGlowShell,trail_color[id][0],trail_color[id][1],trail_color[id][2],kRenderNormal,50)
			
			if(get_pcvar_num(p_avamods_glow_trail) == 1 && in_trail[id] == 1)
				glow_trail(id)
			}
		case 3:
			{
			new color_name[16]
			
			switch(g_MenuPos[id])
				{
				case 0: {
					trail_color[id] = {0,0,255}
					color_name = "Blue"
					}
				case 1: {
					trail_color[id] = {255,140,0}
					color_name = "Orange"
					}
				case 2: {
					trail_color[id] = {255,190,190}
					color_name = "Pink"
					}
				case 3: {
					trail_color[id] = {190,100,10}
					color_name = "Bronze"
					}
				}		
			set_hudmessage(trail_color[id][0],trail_color[id][1],trail_color[id][2], 0.02, 0.73, 0, 6.0, 8.0, 0.1, 0.2, 4) 
			show_hudmessage(id, "you are now glowing %s",color_name)
			set_user_rendering(id,kRenderFxGlowShell,trail_color[id][0],trail_color[id][1],trail_color[id][2],kRenderNormal,50)
			
			if(get_pcvar_num(p_avamods_glow_trail) == 1 && in_trail[id] == 1)
				glow_trail(id)
			}
		case 4:
			{		
			switch(g_MenuPos[id])
				{
				case 0: {
					trail_color[id] = {0,0,136}
					set_hudmessage(trail_color[id][0],trail_color[id][1],trail_color[id][2], 0.02, 0.73, 0, 6.0, 8.0, 0.1, 0.2, 4) 
					show_hudmessage(id, "you are now glowing Dark Blue")
					set_user_rendering(id,kRenderFxGlowShell,trail_color[id][0],trail_color[id][1],trail_color[id][2],kRenderNormal,50)
					
					if(get_pcvar_num(p_avamods_glow_trail) == 1 && in_trail[id] == 1)
						glow_trail(id)
					}
				case 1: {
					trail_color[id] = {222,110,0}
					set_hudmessage(trail_color[id][0],trail_color[id][1],trail_color[id][2], 0.02, 0.73, 0, 6.0, 8.0, 0.1, 0.2, 4) 
					show_hudmessage(id, "you are now glowing Dark Orange")
					set_user_rendering(id,kRenderFxGlowShell,trail_color[id][0],trail_color[id][1],trail_color[id][2],kRenderNormal,50)
					
					if(get_pcvar_num(p_avamods_glow_trail) == 1 && in_trail[id] == 1)
						glow_trail(id)
					}
				case 2: {
					trail_color[id] = {100,0,100}
					set_hudmessage(trail_color[id][0],trail_color[id][1],trail_color[id][2], 0.02, 0.73, 0, 6.0, 8.0, 0.1, 0.2, 4) 
					show_hudmessage(id, "you are now glowing Violet")
					set_user_rendering(id,kRenderFxGlowShell,trail_color[id][0],trail_color[id][1],trail_color[id][2],kRenderNormal,50)
					
					if(get_pcvar_num(p_avamods_glow_trail) == 1 && in_trail[id] == 1)
						glow_trail(id)
					}
				case 3: {
					if(get_pcvar_num(p_avamods_glow_trail) == 1)
						{
						if(in_trail[id] == 0)
							{
							set_hudmessage(trail_color[id][0],trail_color[id][1],trail_color[id][2], 0.02, 0.73, 0, 6.0, 8.0, 0.1, 0.2, 4) 
							show_hudmessage(id, "glow trail turned on")
							glow_trail(id)
							}
						else
							{
							set_hudmessage(trail_color[id][0],trail_color[id][1],trail_color[id][2], 0.02, 0.73, 0, 6.0, 8.0, 0.1, 0.2, 4) 
							show_hudmessage(id, "glow trail already turned on")
							}
						}
					}
				}
			}
		case 5:
			{
			switch(g_MenuPos[id])
				{
				case 0: {
					trail_color[id] = {0,255,255}
					set_hudmessage(trail_color[id][0],trail_color[id][1],trail_color[id][2], 0.02, 0.73, 0, 6.0, 8.0, 0.1, 0.2, 4) 
					show_hudmessage(id, "you are now glowing Light Blue")
					set_user_rendering(id,kRenderFxGlowShell,trail_color[id][0],trail_color[id][1],trail_color[id][2],kRenderNormal,50)
					
					if(get_pcvar_num(p_avamods_glow_trail) == 1 && in_trail[id] == 1)
						glow_trail(id)
					}
				case 1: {
					trail_color[id] = {255,190,90}
					set_hudmessage(trail_color[id][0],trail_color[id][1],trail_color[id][2], 0.02, 0.73, 0, 6.0, 8.0, 0.1, 0.2, 4) 
					show_hudmessage(id, "you are now glowing Light Orange")
					set_user_rendering(id,kRenderFxGlowShell,trail_color[id][0],trail_color[id][1],trail_color[id][2],kRenderNormal,50)
					
					if(get_pcvar_num(p_avamods_glow_trail) == 1 && in_trail[id] == 1)
						glow_trail(id)
					}
				case 2: {
					trail_color[id] = {0,150,255}
					set_hudmessage(trail_color[id][0],trail_color[id][1],trail_color[id][2], 0.02, 0.73, 0, 6.0, 8.0, 0.1, 0.2, 4) 
					show_hudmessage(id, "you are now glowing Aqua")
					set_user_rendering(id,kRenderFxGlowShell,trail_color[id][0],trail_color[id][1],trail_color[id][2],kRenderNormal,50)
					
					if(get_pcvar_num(p_avamods_glow_trail) == 1 && in_trail[id] == 1)
						glow_trail(id)
					}
				case 3: {
					if(get_pcvar_num(p_avamods_glow_trail) == 1)
						{
						if(in_trail[id] == 1)
							{
							set_hudmessage(trail_color[id][0],trail_color[id][1],trail_color[id][2], 0.02, 0.73, 0, 6.0, 8.0, 0.1, 0.2, 4) 
							show_hudmessage(id, "glow trail turned off")
							end_trail(id)
							}
						else
							{
							set_hudmessage(trail_color[id][0],trail_color[id][1],trail_color[id][2], 0.02, 0.73, 0, 6.0, 8.0, 0.1, 0.2, 4) 
							show_hudmessage(id, "glow trail already turned off")
							}
						}
					}
				}
			}
		case 6:
			{
			switch(g_MenuPos[id])
				{
				case 0: {
					trail_color[id] = {0,255,0}
					set_hudmessage(trail_color[id][0],trail_color[id][1],trail_color[id][2], 0.02, 0.73, 0, 6.0, 8.0, 0.1, 0.2, 4) 
					show_hudmessage(id, "you are now glowing Green")
					set_user_rendering(id,kRenderFxGlowShell,trail_color[id][0],trail_color[id][1],trail_color[id][2],kRenderNormal,50)
					
					if(get_pcvar_num(p_avamods_glow_trail) == 1 && in_trail[id] == 1)
						glow_trail(id)
					}
				case 1: {
					trail_color[id] = {150,63,0}
					set_hudmessage(trail_color[id][0],trail_color[id][1],trail_color[id][2], 0.02, 0.73, 0, 6.0, 8.0, 0.1, 0.2, 4) 
					show_hudmessage(id, "you are now glowing Brown")
					set_user_rendering(id,kRenderFxGlowShell,trail_color[id][0],trail_color[id][1],trail_color[id][2],kRenderNormal,50)
					
					if(get_pcvar_num(p_avamods_glow_trail) == 1 && in_trail[id] == 1)
						glow_trail(id)
					}
				case 2: {
					trail_color[id] = {200,0,0}
					set_hudmessage(trail_color[id][0],trail_color[id][1],trail_color[id][2], 0.02, 0.73, 0, 6.0, 8.0, 0.1, 0.2, 4) 
					show_hudmessage(id, "you are now glowing Maroon")
					set_user_rendering(id,kRenderFxGlowShell,trail_color[id][0],trail_color[id][1],trail_color[id][2],kRenderNormal,50)
					
					if(get_pcvar_num(p_avamods_glow_trail) == 1 && in_trail[id] == 1)
						glow_trail(id)
					}
				case 3: {
					trail_color[id] = {0,0,0}
					set_hudmessage(255,255,255, 0.02, 0.73, 0, 6.0, 8.0, 0.1, 0.2, 4) 
					show_hudmessage(id, "you are no longer glowing")
					set_user_rendering(id,kRenderFxGlowShell,trail_color[id][0],trail_color[id][1],trail_color[id][2],kRenderNormal,0)
					
					if(get_pcvar_num(p_avamods_glow_trail) == 1 && in_trail[id] == 1)
						end_trail(id)
					}
				}
			}
		case 7:
			{
			switch(g_MenuPos[id])
				{
				case 0: {
					trail_color[id] = {0,155,0}
					set_hudmessage(trail_color[id][0],trail_color[id][1],trail_color[id][2], 0.02, 0.73, 0, 6.0, 8.0, 0.1, 0.2, 4) 
					show_hudmessage(id, "you are now glowing Dark Green")
					set_user_rendering(id,kRenderFxGlowShell,trail_color[id][0],trail_color[id][1],trail_color[id][2],kRenderNormal,50)
					
					if(get_pcvar_num(p_avamods_glow_trail) == 1 && in_trail[id] == 1)
						glow_trail(id)
					}
				case 1: {
					trail_color[id] = {205,123,64}
					set_hudmessage(trail_color[id][0],trail_color[id][1],trail_color[id][2], 0.02, 0.73, 0, 6.0, 8.0, 0.1, 0.2, 4) 
					show_hudmessage(id, "you are now glowing Light Brown")
					set_user_rendering(id,kRenderFxGlowShell,trail_color[id][0],trail_color[id][1],trail_color[id][2],kRenderNormal,50)
					
					if(get_pcvar_num(p_avamods_glow_trail) == 1 && in_trail[id] == 1)
						glow_trail(id)
					}
				case 2: {
					trail_color[id] = {255,255,255}
					set_hudmessage(trail_color[id][0],trail_color[id][1],trail_color[id][2], 0.02, 0.73, 0, 6.0, 8.0, 0.1, 0.2, 4) 
					show_hudmessage(id, "you are now glowing White")
					set_user_rendering(id,kRenderFxGlowShell,trail_color[id][0],trail_color[id][1],trail_color[id][2],kRenderNormal,50)
					
					if(get_pcvar_num(p_avamods_glow_trail) == 1 && in_trail[id] == 1)
						glow_trail(id)
					}
				case 3: {
					g_MenuPos[id] = 3
					GlowMenuMenu(id, g_MenuPos[id])
					}
				}
			}
		case 8: 
			{
			switch(g_MenuPos[id])
				{
				case 0: {
					trail_color[id] = {180,255,175}
					set_hudmessage(trail_color[id][0],trail_color[id][1],trail_color[id][2], 0.02, 0.73, 0, 6.0, 8.0, 0.1, 0.2, 4) 
					show_hudmessage(id, "you are now glowing Light Green")
					set_user_rendering(id,kRenderFxGlowShell,trail_color[id][0],trail_color[id][1],trail_color[id][2],kRenderNormal,50)
					
					if(get_pcvar_num(p_avamods_glow_trail) == 1 && in_trail[id] == 1)
						glow_trail(id)
					}
				case 1: {
					g_MenuPos[id] = 0
					GlowMenuMenu(id, g_MenuPos[id])
					}
				case 2: {
					g_MenuPos[id] = 1
					GlowMenuMenu(id, g_MenuPos[id])
					}
				case 3: {
					g_MenuPos[id] = 2
					GlowMenuMenu(id, g_MenuPos[id])
					}
				}
			}
		case 9:
			{ 
			switch(g_MenuPos[id])
				{
				case 0: {
					g_MenuPos[id] = 1
					GlowMenuMenu(id, g_MenuPos[id])
					}
				case 1: {
					g_MenuPos[id] = 2
					GlowMenuMenu(id, g_MenuPos[id])
					}
				case 2: {
					g_MenuPos[id] = 3
					GlowMenuMenu(id, g_MenuPos[id])
					}
				case 3: return PLUGIN_HANDLED	
				}
			}		
		}
	}
   return PLUGIN_CONTINUE
}

public glow_trail(id)
{
	if(!is_user_connected(id) || !is_user_alive(id) || is_user_bot(id) || get_pcvar_num(p_avamods_glow_trail) != 1 || get_pcvar_num(p_avamods_glow) != 1)
		return PLUGIN_HANDLED

	if(task_exists(TASK_TRAIL+id))
		remove_task(TASK_TRAIL+id)
		
	message_begin(MSG_BROADCAST, SVC_TEMPENTITY)		
	write_byte(99)							// kill all beams attached to entity 
	write_short(id) 						// entity
	message_end()

	message_begin(MSG_BROADCAST, SVC_TEMPENTITY)		
	write_byte(22)							// TE_BEAMFOLLOW 22		
	write_short(id)							// short (entity:attachment to follow)
	write_short(g_Sprite) 						// short (sprite index)
	write_byte(get_pcvar_num(p_avamods_glow_trail_length)*10)		// byte (life in 0.1's) 
	write_byte(8)							// byte (line width in 0.1's) 
	write_byte(trail_color[id][0])					// byte (color)
	write_byte(trail_color[id][1])					// byte (color)	
	write_byte(trail_color[id][2])					// byte (color)
	write_byte(100)							// byte (brightness)
	message_end()
	
	if(in_trail[id] == 0)
		in_trail[id] = 1

	set_task(get_pcvar_float(p_avamods_glow_trail_length), "refresh_trail", TASK_TRAIL+id)
	
	return PLUGIN_CONTINUE
}

public refresh_trail(id)
{
	id = id-TASK_TRAIL

	if(get_pcvar_num(p_avamods_glow) != 1 || get_pcvar_num(p_avamods_glow_trail) != 1 || in_trail[id] == 0 || !is_user_alive(id) || !is_user_connected(id) || is_user_bot(id))
		{
		if(task_exists(TASK_TRAIL+id))
			{
			message_begin(MSG_BROADCAST, SVC_TEMPENTITY)		
			write_byte(99)					// kill all beams attached to entity 
			write_short(id) 				// entity
			message_end()
			
			remove_task(TASK_TRAIL+id)
			}
		return PLUGIN_HANDLED
		}

	message_begin(MSG_BROADCAST, SVC_TEMPENTITY)		
	write_byte(22)							// TE_BEAMFOLLOW 22		
	write_short(id)							// short (entity:attachment to follow)
	write_short(g_Sprite) 						// short (sprite index)
	write_byte(get_pcvar_num(p_avamods_glow_trail_length)*10)	// byte (life in 0.1's) 
	write_byte(8)							// byte (line width in 0.1's) 
	write_byte(trail_color[id][0])					// byte (color)
	write_byte(trail_color[id][1])					// byte (color)	
	write_byte(trail_color[id][2])					// byte (color)
	write_byte(45)							// byte (brightness)
	message_end()
	
	set_task(get_pcvar_float(p_avamods_glow_trail_length), "refresh_trail", TASK_TRAIL+id)
	
	return PLUGIN_CONTINUE
}

public end_trail(id)
{	
	if(!is_user_connected(id) || get_pcvar_num(p_avamods_glow_trail) != 1 || get_pcvar_num(p_avamods_glow) != 1 || in_trail[id] == 0)
		return PLUGIN_HANDLED

	if(task_exists(TASK_TRAIL+id))
		remove_task(TASK_TRAIL+id)
		
	if(in_trail[id] == 1)
		in_trail[id] = 0
		
	message_begin(MSG_BROADCAST, SVC_TEMPENTITY)		
	write_byte(99)							// kill all beams attached to entity 
	write_short(id) 						// entity
	message_end()

	return PLUGIN_CONTINUE
}

public respawn(id)
{
	if(get_pcvar_num(p_avamods_glow) != 1 || !is_user_alive(id) || !is_user_connected(id) || is_user_bot(id) || get_pcvar_num(p_avamods_glow_trail) != 1 || in_trail[id] == 0)
		return PLUGIN_CONTINUE
		
	set_task(1.0, "refresh_trail", TASK_TRAIL+id)

	return PLUGIN_CONTINUE
}

public client_death(killer,victim,wpnindex,hitplace,TK)
{
	if(get_pcvar_num(p_avamods_glow) != 1 || get_pcvar_num(p_avamods_glow_trail) != 1 || in_trail[victim] == 0 || !is_user_connected(victim) || is_user_alive(victim) || is_user_bot(victim))
		return PLUGIN_CONTINUE

	message_begin(MSG_BROADCAST, SVC_TEMPENTITY)		
	write_byte(99)							// kill all beams attached to entity 
	write_short(victim) 						// entity
	message_end()
		
	if(task_exists(TASK_TRAIL+victim))
		remove_task(TASK_TRAIL+victim)
	
	return PLUGIN_CONTINUE
}

public switch_team()
{
	new name[32]
	read_data(3,name,31)
	new id = get_user_index(name)
	
	if(get_pcvar_num(p_avamods_glow) != 1 || get_pcvar_num(p_avamods_glow_trail) != 1 || in_trail[id] == 0 || !is_user_connected(id) || is_user_alive(id) || is_user_bot(id))
		return PLUGIN_CONTINUE
	
	message_begin(MSG_BROADCAST, SVC_TEMPENTITY)		
	write_byte(99)							// kill all beams attached to entity 
	write_short(id) 						// entity
	message_end()
		
	if(task_exists(TASK_TRAIL+id))
		remove_task(TASK_TRAIL+id)
	
	return PLUGIN_CONTINUE
}
